import operate from '@dfeidao/atom-nodejs/db/operate';
import log from '@dfeidao/atom-nodejs/logger/log';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import { systemid } from '../../atom/config';
interface Message {
	training_name: string;
	lecturer_number: string;
	lecturer_name: string;
	train_start_time: string;
	training_time: string;
	training_location: string;
	training_content: string;
	to_state: string;
	take_effect: string;
	supposed_come_peo_num: string;
	attendance: string;
	training_conclusion: string;
}


// 表名	train_plan
// 标题	培训计划
// 字段名称	字段标题	字段类型	字段长度	是否为空	是否主键
// _id	id	string	50	ⅹ	√
// productid	产品ID	string	50	√	ⅹ
// train_number	培训编号	string	32	√	ⅹ
// training_name	培训名称	string	64	√	ⅹ
// lecturer_number	讲师编号	string	32	√	ⅹ
// lecturer_name	讲师姓名	string	16	√	ⅹ
// train_start_time	培训开始时间	timestamp	50	√	ⅹ
// training_time	培训结束时间	timestamp	50	√	ⅹ
// training_location	培训地点	string	64	√	ⅹ
// training_content	培训内容	string	512	√	ⅹ
// to_state	进行状态	int	16	√	ⅹ
// take_effect	是否生效	int	16	√	ⅹ
// supposed_come_peo_num	应到人数	int	32	√	ⅹ
// attendance	实到人数	int	32	√	ⅹ
// training_conclusion	培训结论	string	256	√	ⅹ

export default async function atom(msg: Message, action_id: string, session_id: string) {
	log(`Service begin`);
	const { exec, insert } = await operate(action_id, session_id, systemid);
	const { result } = await doc_code(action_id, session_id, systemid, 'BM0014260', '', 1);
	insert('train_plan', { 'train_number': result, 'training_name': msg.training_name, 'lecturer_number': msg.lecturer_number, 'lecturer_name': msg.lecturer_name, 'train_start_time': msg.train_start_time, 'training_time': msg.training_time, 'training_location': msg.training_location, 'training_content': msg.training_content, 'to_state': msg.to_state, 'take_effect': msg.take_effect, 'supposed_come_peo_num': msg.supposed_come_peo_num, 'attendance': msg.attendance, 'training_conclusion': msg.training_conclusion });
	const res = await exec();
	log(`Service end`);
	return { res, result };
}
